package aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author td
 * @date 2018/6/4
 */
public class TimerInterceptor implements MethodInterceptor {

    public Object invoke(MethodInvocation methodInvocation) throws Throwable {

        long startTime = System.currentTimeMillis();
        System.out.println("Invocation of Method " + methodInvocation.getMethod().getName() + " start!");

        Object object = methodInvocation.proceed();
        System.out.println("Invocation of Method " + methodInvocation.getMethod().getName()+ "end! takes + "
                + (System.currentTimeMillis()-startTime)+ "seconds.");

        return object;
    }
}
